package com.feng.test.html;

import java.nio.charset.StandardCharsets;
import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.util.NodeIterator;
import org.htmlparser.util.ParserException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * @author HuangSuip
 */
public class HtmlAnalyse {
    public static void main(String[] args) throws ParserException {

        String html = "<p>Hey this <strong>editor</strong> rocks \uD83D\uDE00</p><img src=\"http://img.zcool.cn/community/0142135541fe180000019ae9b8cf86.jpg@1280w_1l_2o_100sh.png\" alt=\"undefined\" style=\"float:none;height: auto;width: auto\"/>\n<p></p>";
        Parser parser = Parser.createParser(html, StandardCharsets.UTF_8.displayName());
        NodeIterator elements = parser.elements();
        while (elements.hasMoreNodes()){
            Node node = elements.nextNode();
            message("getText:"+node.getText());
            message("getPlainText:"+node.toPlainTextString());
            message("toHtml:"+node.toHtml());
            message("toHtml(true):"+node.toHtml(true));
            message("toHtml(false):"+node.toHtml(false));
            message("toString:"+node.toString());

        }
        System.out.println(elements.hasMoreNodes());

/*        StringExtractor extractor;
        SiteCapturer capturer;*/
    }
    private  static void message(Object o){
        System.out.println(o);
    }
}

class HtmlAnalyse2{
    public static void main(String[] args) {
        String html = "agafafafa";
        Document doc = Jsoup.parseBodyFragment(html);
        message(doc.nodeName());
        //message(doc.body());

        Elements img = doc.getElementsByTag("img");
        for (int i = 0; i < img.size(); i++) {
            img.get(i).attr("src","ceshi");
        }
        message(img.attr("src"));
        message(doc);
        message(doc.getElementsByTag("body"));
    }
    private  static void message(Object o){
        System.out.println(o);
        System.out.println();
    }
}
